package main

import (
	"Logger/logTransfer/config"
	"Logger/logTransfer/etcd"
	"Logger/logTransfer/kafka"
	"github.com/sirupsen/logrus"
	"github.com/spf13/viper"
)

func main() {
	//1.初始化，读取配置文件
	err := config.Init()
	if err != nil {
		logrus.Fatal("config init failed,", err)
	}
	//2.初始化etcd
	err = etcd.Init([]string{viper.GetString("etcd.address")})
	if err != nil {
		logrus.Fatal("etcd init failed,", err)
	}
	//3.从etcd拉取要消费的配置（topics）
	topics, _ := etcd.GetTopics(viper.GetString("etcd.key"))
	//4.初始化kafka消费者组，开始消费
	//err = kafka.InitConsumerGroup([]string{viper.GetString("kafka.address")}, topics)
	//if err != nil {
	//	logrus.Fatal("kafka init failed,", err)
	//}
	//5.初始化消费者，开始消费数据
	err = kafka.InitConsumer([]string{viper.GetString("kafka.address")}, topics, viper.GetString("etcd.key"))
	if err != nil {
		logrus.Fatal("kafka init failed,", err)
	}
	//阻塞，持续消费
	select {}
}
